/*
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Library General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
*/

#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include "ui_mainwindow.h"
#include "searchboximpl.h"

#include "datamodel.h"
#include "stylemodel.h"
#include "configurationmodel.h"
#include "templatesmodel.h"
#include "helpdlgimpl.h"
#include "constantes.h"

#include <QSystemTrayIcon>
//

class QComboBox;
class QFontComboBox;

class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
    Q_OBJECT
public:
    MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );

protected:
    void closeEvent(QCloseEvent *event);

private slots:
	void on_actionSave_as_template_triggered();
	void on_actionTemplates_manager_triggered();
	void on_actionModify_table_triggered();
	void on_actionInsert_table_triggered();
	void on_actionInsert_image_triggered();
	void on_actionInsert_current_time_triggered();
	void on_actionInsert_current_date_triggered();
    void on_actionHelp_triggered();
    void on_action_Search_triggered();
    void on_action_Options_triggered();
    void on_action_Apply_current_style_triggered();
    void on_actionStyle_editor_triggered();
    void on_actionPostScript_triggered();
    void on_actionExport_PDF_triggered();
    void on_actionPrint_triggered();
    void on_action_About_triggered();
    void on_actionAbout_Qt_triggered();
    void on_textEdit_cursorPositionChanged();
    void on_action_Color_triggered();
    void onClipboardDataChanged();
    void onTextFamily(const QString &f);
    void onTextSize(const QString &p);
    void onTextAlign(QAction *a);
    void on_textEdit_currentCharFormatChanged(QTextCharFormat format);
    void on_actionBold_triggered();
    void on_actionItalic_triggered();
    void on_actionUnderline_triggered();
    void on_action_New_triggered();
    void on_action_Save_triggered();
    void on_actionSave_as_triggered();
    void on_action_Open_triggered();
    void on_action_Quit_triggered();

	void onSelectStyle(QAction *a);
	void onComboSelectStyle(QString name);

    void onActionMenuRename();
    void onActionMenuDelete();
    void onActionMenuAddCategory();
    void onActionMenuAddPage();

    void onActionMenuMoveLeft();
    void onActionMenuMoveRight();
    void onActionMenuMoveUp();
    void onActionMenuMoveDown();

    void onActionAddRootCategory();
    void onActionAddRootPage();

    void onActionMenuProperty();

    void onActionSysClose();
    void onActionSysShow();
    void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);

    void onTreeClick(QTreeWidgetItem *treeItem, int col);
    void onTreeContextMenuRequested(QPoint pos);
    void onCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);

    void onSearchSelection(QTreeWidgetItem *treeItem, int selStart, int selLenght);
    
    void onInsertTemplate();

private:

    SearchBoxImpl *searchBox;
    QDockWidget *searchDock;
    QDockWidget *treeDock;

    QTreeWidget *treeWidget;
    QToolBar *treeToolBar;

    Model *mainModel;
    StyleManager *m_styleManager;
    ConfigurationManager *m_confManager;
    TemplateManager *m_templatesManager;

    QSystemTrayIcon *m_trayIcon;
    bool m_closeFromMenu;

    QFontComboBox *comboFont;
    QComboBox *comboSize;

	QActionGroup *m_stylesGroup;
	QAction *m_templatesArray[Constantes::NB_MAX_TEMPLATES];
	QAction *m_stylesArray[Constantes::NB_MAX_STYLES];

    QToolBar *fontToolBar;
    QToolBar *styleToolBar;
    QToolBar *insertToolBar;
    
    QAction *actionAlignLeft;
    QAction *actionAlignRight;
    QAction *actionAlignCenter;
    QAction *actionAlignJustify;
    
    QComboBox *comboStyle;

    QAction *actionAddRootCategory;
    QAction *actionAddRootPage;

    QAction *actionMenuAddCategory;
    QAction *actionMenuAddPage;
    QAction *actionMenuRename;
    QAction *actionMenuDelete;
    QAction *actionMenuMoveLeft;
    QAction *actionMenuMoveRight;
    QAction *actionMenuMoveUp;
    QAction *actionMenuMoveDown;
    QAction *actionMenuProperty;
    QMenu *contextMenu;

    QAction *actionSysShow;
    QAction *actionSysClose;
    QMenu *sysTrayMenu;

    HelpDlgImpl *helpDlg;

    void createTreeDock();
    void createSearchDock();
    void createToolBars();
    void createContextMenu();
    void createSysTray();
    void FinalizeUI();

    void openFile(QString fileName);

    void readSettings();
    void writeSettings();

    void doClose();
    void doCloseToTray();

    void setEditorColor(QColor color);
    void setTreeColor(QColor color);

    void applyConfiguration();

    void setEmptyFileDisplay();

    void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
    void onFontChanged(const QFont &f);
    void onColorChanged(const QColor &c);
    void onAlignmentChanged(Qt::Alignment a);

	void initTemplateActionList();
	void updateTemplateActionList();
	
	void updateStylesActionList();

};
#endif











